import React from "react"
import url from 'url'
import {Button, WhiteSpace} from "antd-mobile";

function TimeDown(endDateStr) {
    //结束时间
    var endDate = new Date(endDateStr);
    //当前时间
    var nowDate = new Date();
    //相差的总秒数
    var totalSeconds = parseInt((endDate - nowDate) / 1000);
    //天数
    var days = Math.floor(totalSeconds / (60 * 60 * 24));
    return days
}

export default class MyMail extends React.Component {
    state = {
        days: 9999
    }

    componentDidMount() {

        console.log(this.props.location.search)

        if (this.props.location.search) {
            const days = TimeDown(url.parse(this.props.location.search, true).query.sendtime)
            this.setState({
                days: days
            })
        }
    }

    render() {
        const style = {
            position: 'absolute',
            top: '50%',
            marginTop: '-50%',
            marginLeft: '10%',
            marginRight: '10%',
            fontSize: '24px',
            color: '#86c4cd',
            textAlign: "center"
        }

        return (
            <div style={style}>
                <img style={{width:'100%'}} src="/img/tj/资源 35@2x.png" alt=""/>
                <WhiteSpace/>
                <b>距离重逢还有{this.state.days}天</b>
                <WhiteSpace/>
                <WhiteSpace/>
                <Button onClick={this.goHome} style={{width:'50%', marginLeft: '25%'}} size="small" type="primary">返回首页</Button>
            </div>
        )
    }

    goHome = () => {
        this.props.history.push('/')
    }
}